package cate.common.table.item.fairy.row;

import cate.common.table.EExcelNoteField;
import cate.common.table.EExcelRowClass;
import cate.common.table.ERow;
import cate.common.table.item.IBagItemTpl;
import org.apache.commons.lang3.StringUtils;

import java.util.HashSet;
import java.util.Set;

@EExcelRowClass(IDTitle = "灵器ID")
public class FairyBaseRow extends ERow implements IBagItemTpl {

    @EExcelNoteField(fieldName = "原型ID")
    public int protoId;

    @EExcelNoteField(fieldName = "下一级ID")
    public int nextTid;

    @EExcelNoteField(fieldName = "名称")
    public String name;

    @EExcelNoteField(fieldName = "等级")
    public int level;

    @EExcelNoteField(fieldName = "类型")
    public byte type;

    @EExcelNoteField(fieldName = "属性")
    public String attrStr;

    @EExcelNoteField(fieldName = "专属英雄")
    private String heroStr;

    @EExcelNoteField(fieldName = "专属技能")
    private String skillStr;

    @EExcelNoteField(fieldName = "阵营", defaultValue = "0")
    public byte camp;

    @EExcelNoteField(fieldName = "分解返还")
    public String returnStr;

    @EExcelNoteField(fieldName = "升级道具消耗")
    public String levelUpCost1;

    @EExcelNoteField(fieldName = "升级资源消耗")
    public String levelUpCost2;

    @EExcelNoteField(fieldName = "碎片合成道具消耗")
    public String composeCost1;

    @EExcelNoteField(fieldName = "回炉花费")
    public String backCostStr;

    @EExcelNoteField(fieldName = "回炉返还")
    public String backRwdStr;

    @EExcelNoteField(fieldName = "是否可回收")
    public boolean allowRecycle;

    @EExcelNoteField(fieldName = "回收返还")
    public String recycleStr;

    public Set<Integer> heros;

    public Set<Integer> skills;

    @Override
    public String getName() {
        return name;
    }

    @Override
    public int getTemplateId() {
        return id;
    }

    @Override
    public long getPileMax() {
        return 1;
    }

    @Override
    public boolean unique() {
        return true;
    }

    @Override
    public void decode() {
        heros = new HashSet<>();
        if (StringUtils.isNotBlank(heroStr)) {
            for (String s : heroStr.split("#")) {
                heros.add(Integer.parseInt(s));
            }
        }
        skills = new HashSet<>();
        if (StringUtils.isNotBlank(skillStr)) {
            for (String s : skillStr.split("#")) {
                skills.add(Integer.parseInt(s));
            }
        }
    }

    /**
     * 仙器是否专属于这个英雄
     *
     * @param protoId
     * @return
     */
    public boolean isExclusive(int protoId) {
        return !heros.isEmpty() && heros.contains(protoId);
    }
}
